package com.lezhu.plcsdklibrary.manager;

import com.lezhu.plcsdklibrary.callback.DoorListener;

import java.util.ArrayList;

/**
 * 描述:所有柜门状态回调管理
 * 作者: 钮家齐
 * 时间: 2020/6/1 9:11
 */
public class DoorStatusCallBackManager {

    private static ArrayList<DoorListener> list;
    private static DoorStatusCallBackManager doorStatusCallBackManager;

    public static DoorStatusCallBackManager getInstance(){
        if(doorStatusCallBackManager==null){
            synchronized (DoorStatusCallBackManager.class){
                if(doorStatusCallBackManager==null){
                    doorStatusCallBackManager = new DoorStatusCallBackManager();
                    list = new ArrayList<>();
                }
            }
        }
        return doorStatusCallBackManager;
    }


    public void addDoorListener(DoorListener statusInterface){
        list.add(statusInterface);
    }


    public void removeDoorListener(DoorListener statusInterface){
        if(list.contains(statusInterface)){
            list.remove(statusInterface);
        }
    }

    public void doorOpen(int pos){
        for(DoorListener doorListener: list){
            doorListener.doorOpen(pos);
        }
    }

    public void doorClose(int pos){
        for(DoorListener doorListener: list){
            doorListener.doorClose(pos);
        }
    }
}
